package com.ruoyi.web.controller.wechat;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.wechat.service.ICaptchaService;
import com.ruoyi.system.service.ISysDictTypeService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author cj
 */
@Api("微信接口-ruoyi-system")
@RestController
@RequestMapping("/wechat/system")
public class WeChatSystemController {

    @Autowired
    private ICaptchaService captchaService;


    @Autowired
    private ISysDictTypeService dictTypeService;


    /**
     * 生成验证码
     */
    @GetMapping("/captchaImage")
    public AjaxResult getCode() throws IOException {
        return captchaService.getImgCode();
    }

    /**
     * 根据字典类型查询字典数据信息
     */
    @ResponseBody
    @GetMapping(value = "/dict/data/dictType/{dictType}")
    public AjaxResult dictType(@PathVariable String dictType)
    {
        List<SysDictData> data = dictTypeService.selectDictDataByType(dictType);
        if (StringUtils.isNull(data))
        {
            data = new ArrayList<SysDictData>();
        }
        return AjaxResult.success(data);
    }


}
